package hhf.common.acid.service {
	import hhf.common.acid.event.ServiceEvent;
	
	import mx.core.Application;
	import mx.core.mx_internal;

	use namespace mx_internal;

	public class ServicesManager {
		public var services:Array;
		public function ServicesManager() {
			services = new Array();
			Application.application.addEventListener(ServiceEvent.ASK_INJECTION, function(event:ServiceEvent):void {
				var target:Service = event.serviceTarget;
				var id:String = event.id;
				services.forEach(function(elts:*, index:int, arr:Array):void {
					var elements:Object = elts as Object;
					var target:Service = this.serviceTarget;
					var id:String = this.id;
					if(elements!=null&&elements.hasOwnProperty(id)) { 
						target.mx_internal::bean = elements[id];
						return;
					}
				}, event);
				if(target.mx_internal::bean ==null) throw new Error("unknown service "+id);
 			}, false);
		}
	}
}